import React from 'react';
import { inject, observer } from 'mobx-react';
import { withRouter } from 'react-router-dom';
import { List, Tools } from 'weaver-mobile';
import { ListViewPage } from 'weaver-mobile-page';

const getLabel = Tools.getLabel;

@inject('userCenterStore')
@withRouter
@observer
export default class DefaultShare extends React.Component {
  static defaultProps = {
    prefixCls: 'blog-userCenter-shareSet-default',
  }

  render() {
    const { prefixCls, userCenterStore: { userShareSetStore } } = this.props;
    const { defaultShareList } = userShareSetStore;

    const separator = (sectionID, rowID) => {
      return rowID == 0 && defaultShareList.data.length > 1 ? (<div
        key={`${sectionID}-${rowID}`} style={{color:'black'}}
        className={`${prefixCls}-separator`}
      >{getLabel(131260,'指定共享')}</div>):'';
    };

    const sectionData = (sectionData) => (
      <div style={{color:'black'}} className={`${prefixCls}-sectionData`}>{getLabel(596,'上级')}</div>
    );

    const runRow = (rowData, sectionID, rowID) => {
      if(rowData.canViewMinTime && rowData.canViewMinTime != '0' && rowData.canViewMinTime != '-1'){
        return (
          <List.Item key={rowID}>
            {/* <div className={`${prefixCls}-time`}>{rowData.shareType2span}</div> */}
            <div style={{width: 'inherit',display: 'block',whiteSpace: 'normal'}} className={`${prefixCls}-time`}>{rowData.shareType2span + rowData.shareType3span}
                </div>
            <div className={`${prefixCls}-time`}>{getLabel('509722','起止可查看时间') } {rowData.canViewMinTime}</div>
                      
          </List.Item>
        );
      }else{
        return (
          <List.Item key={rowID}>
            <div style={{width: 'inherit',display: 'block',whiteSpace: 'normal'}} className={`${prefixCls}-listItem`}>{rowData.shareType2span}</div>
          </List.Item>
        );
      }
    };

    return (
      <ListViewPage.Normal 
        key='keyDafaultShare'
        store={defaultShareList}
        className={prefixCls}
        renderSectionHeader={sectionData} 
        renderSeparator={separator} 
        renderRow={runRow}
        pageSize={20}
        initialListSize={20}
      />
    )
  }
}